// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import { ExtensionContext, window, commands } from "vscode";
import Provider from "./Provider";
import { removeFund, showInfomationMesage } from "./utils";

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: ExtensionContext) {
  // const interval = Math.max(
  //   workspace.getConfiguration().get("fund-watch.interval", 2),
  //   2
  // );

  // new一个基金类实例
  const provider = new Provider();
  showInfomationMesage();

  // 注册数据
  window.registerTreeDataProvider("fund-list", provider);
  // The command has been defined in the package.json file
  // Now provide the implementation of the command with registerCommand
  // The commandId parameter must match the command field in package.json
  // let disposable = commands.registerCommand('fund.helloWorld', () => {
  // 	// The code you place here will be executed every time your command is executed
  // 	// Display a message box to the user
  // 	window.showInformationMessage('Hello World from !');
  // });

  // context.subscriptions.push(disposable);

  // 定时任务，自动刷新数据
  // setInterval(() => {
  //   // provider.refresh();
  //   const tips = [
  //     "靓仔，睇下宜家几时啦",
  //     "靓仔，仲唔加仓？",
  //     "-----------------------",
  //     "7头，唔系做啦，做咁多，可以发过猪肉荣吗？",
  //   ];
  //   window.showInformationMessage(tips.join("\r\n"));
  // }, interval * 10000);

  // menu事件
  context.subscriptions.push(
    commands.registerCommand("fund.add", () => {
      provider.addFund();
    }),
    commands.registerCommand("fund.order", () => {
      provider.changeOrder();
    }),
    commands.registerCommand("fund.refresh", () => {
      provider.refresh();
    }),
    commands.registerCommand("fund.item.remove", (fund: FundInfo) => {
      const { code } = fund;
      removeFund(code);
      provider.refresh();
    })
  );
}

// this method is called when your extension is deactivated
export function deactivate() {}
